﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GaduBot
{
    public partial class Form1 : Form
    {
        private GaduBot.Properties.Settings AppSets = new GaduBot.Properties.Settings();
        
        ///<summary>
        /// Konstruktor klasy Form1
        ///</summary>
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!System.IO.File.Exists(Application.StartupPath + "\\noconnect.txt"))
            {
                this.Gadu.Destroy();
            }
            if (System.IO.File.Exists(Application.StartupPath + "\\noconnect.txt"))
            {
                System.IO.File.Delete(Application.StartupPath + "\\noconnect.txt");
            }
            Application.Exit();
        }

        private void button1_Click(object sender, EventArgs e)
        {
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (!System.IO.File.Exists(Application.StartupPath + "\\noconnect.txt"))
            {
                this.Gadu = new GaduC(this.richTextBox1,this.dataGridView1);
            }
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;

            this.textBox3.Text = this.AppSets.GaduServerAddr;
            this.textBox4.Text = this.AppSets.GaduServerPort.ToString();
            this.textBox5.Text = this.AppSets.GaduNumber.ToString();
            this.textBox6.Text = this.AppSets.GaduPass;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.AppSets.GaduServerAddr = this.textBox3.Text;
            this.AppSets.GaduServerPort = int.Parse(this.textBox4.Text);
            this.AppSets.GaduNumber  = int.Parse(this.textBox5.Text);
            this.AppSets.GaduPass = this.textBox6.Text;
            this.AppSets.Save();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox1 box = new AboutBox1();
            box.Show();
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            System.Threading.Thread.Sleep(1000);
            System.Diagnostics.Process.GetCurrentProcess().Kill();
            Application.Exit();
        }

        private void notifyIcon1_Click(object sender, EventArgs e)
        {
            this.Show();
        }

        private void wylaczToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(1000);
            System.Diagnostics.Process.GetCurrentProcess().Kill();
            Application.Exit();
        }

        private void searchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process.Start("GNU GPL License.txt");
            }
            catch (Exception)
            {
                System.Diagnostics.Process.Start("http://www.gnu.org/licenses/gpl-3.0.txt");
            }
        }

        private void dataGridView1_UserAddedRow(object sender, DataGridViewRowEventArgs e)
        {

        }

        private void toolStripProgressBar1_Click(object sender, EventArgs e)
        {

        }

        private void helpToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://code.google.com/p/gadubot/wiki/Pomoc");
        }

        private void supportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://code.google.com/p/gadubot/issues/entry");
        }
    }
}
